package framework.input;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;

/**
 * FEITA Classe para gerenciar o acesso aos dados do acelerometro
 * 
 * @author lucas
 * 
 */
public class AccelerometerInput implements SensorEventListener {
	float x;
	float y;
	float z;

	public AccelerometerInput(Context context) {
		SensorManager manager = (SensorManager) context
				.getSystemService(Context.SENSOR_SERVICE);
		try {
			Sensor sensor = manager.getSensorList(Sensor.TYPE_ACCELEROMETER)
					.get(0);
			manager.registerListener(this, sensor,
					SensorManager.SENSOR_DELAY_GAME);
		} catch (Exception e) {
			Log.v("INPUT", "Impossível acessar o Sensor");
		}
	}

	/**
	 * Atualiza os valores de x,y,z do sensor.
	 */
	@Override
	public void onSensorChanged(SensorEvent event) {
		this.x = event.values[0];
		this.y = event.values[1];
		this.z = event.values[2];
	}

	public float getX() {
		return this.x;
	};

	public float getY() {
		return this.y;
	};

	public float getZ() {
		return this.z;
	};

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// / não serve para nada
	}

}
